#-*-coding:utf8;-*-
from stockSelect10_soup_phone import getstock
import pandas as pd
"""
M:=55;
N:=34;
LC:=REF(CLOSE,1);
RSI:=((SMA(MAX((CLOSE - LC),0),3,1) / SMA(ABS((CLOSE - LC)),3,1)) * 100);
FF:=EMA(CLOSE,3);
MA15:=EMA(CLOSE,21);
DRAWTEXT(CROSS(85,RSI),75,'▼'),COLORGREEN;
VAR1:=IF(YEAR>=2038 AND MONTH>=1,0,1);
VAR2:=REF(LOW,1)*VAR1;
VAR3:=SMA(ABS(LOW-VAR2),3,1)/SMA(MAX(LOW-VAR2,0),3,1)*100*VAR1;
VAR4:=EMA(IF(CLOSE*1.3,VAR3*10,VAR3/10),3)*VAR1;
VAR5:=LLV(LOW,30)*VAR1;
VAR6:=HHV(VAR4,30)*VAR1;
VAR7:=IF(MA(CLOSE,58),1,0)*VAR1;
VAR8:=EMA(IF(LOW<=VAR5,(VAR4+VAR6*2)/2,0),3)/618*VAR7*VAR1;
吸筹:IF(VAR8>100,100,VAR8)*VAR1,COLORRED;
庄家吸筹:STICKLINE(吸筹>-150,0,吸筹,8,0),COLORRED;
散户: 100*(HHV(HIGH,M)-CLOSE)/(HHV(HIGH,M)-LLV(LOW,M)),COLORFFFF00,LINETHICK2;
RSV:=(CLOSE-LLV(LOW,N))/(HHV(HIGH,N)-LLV(LOW,N))*100;
K:=SMA(RSV,3,1);
D:=SMA(K,3,1);
J:=3*K-2*D;
庄家:EMA(J,6),COLORFF00FF,LINETHICK2;
第一买点:DRAWTEXT(CROSS(14,吸筹),10, '买1'),COLORYELLOW;
第二买点:DRAWTEXT(CROSS(庄家,散户) AND 庄家<50,30, '买2'),COLORRED;
第一卖点:DRAWTEXT(CROSS(88,庄家),80, '卖1'),COLORGREEN;
第二卖点:DRAWTEXT(CROSS(散户,庄家),60, '卖2'),COLORCYAN;
"""
code='600691'
gs=getstock(code)
m=55
n=34

#用7天数据参与预测                        
days=7                                    
df=gs.dayN(days)                         
#获得7天数据，由近到远                    
high=df["high"]
close=df["close"]
open_=df["open"]

def ref(series,n):
    return(series.values[-n])
#print(ref(Yh,2))              
def ma(series,window):
    return series.rolling(window).mean()
#print(ma(Yh))
#print(Yh.rolling(3))
print(close)
def ema(series,N):
    """
    若Yn=EMA(Xn，N)，则Yn=[2*Xn+(N-1)*Yn-1]/(N+1)，其中Yn-1表示上一周期的Y值。
    """
    ema_=[]
    for i in range(len(series)):
        if i<1:
            ema_.append(series[0])
        else:
            ema_.append(round(2*series[i]/(N+1)+(N-1)/(N+1)*ema_[i-1],2))
    return ema_

def sma(series,N,M):
    """
    #
    SMA(X，N，M) X的N日累积平均，M为权重
    如Y=(XM+Y(N-M))/N
    """
    sma_=[]
    for i in range(len(series)):
        if i<1:
            sma_.append(series[0])
        else:
            sma_.append(round((M*series[i]+(N-M)*sma_[i-1])/N,2))
    return sma_
def subtraction(series,x):
    return [round(i-x,2) for i in series.values]

def max_(series,x):
    return [max(i,x) for i in series.values]    
def abs_(series,x):
    return [abs(i-x) for i in series.values]
lc1=ref(close,2)
lc2=gs.pre_close
print(lc1,lc2)
#RSI:=((SMA(MAX((CLOSE - LC),0),3,1) / SMA(ABS((CLOSE - LC)),3,1)) * 100);
